﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;


using AIPASoft.DataProvider;
using AIPASoft.Interfaces.Security;
using AIPASoft.Interfaces.Base;

namespace SecurityDataProviderTests
{
    [TestClass]
    public class SecDataProviderTests
    {
        [TestCategory("Role Entity")]
        [TestMethod]
        public void AddNewRole()
        {
            var result = "";
            var sp = new SecurityDataProvider();
            IRole role = sp.CreateNewRole();
            role.RoleName = "Default2";
            DataProviderOperationResult opRes = sp.AddRole(role, out result);

            Assert.AreEqual(DataProviderOperationResult.Success,opRes); 

        }

        [TestCategory("Role Entity")]
        [TestMethod]
        public void DeleteInvalidRole()
        {
            var result = "";
            var sp = new SecurityDataProvider();
            var res = sp.DeleteRole(100, out result);
            Assert.AreEqual(DataProviderOperationResult.RecordNotFoundError,res);
        }

        [TestCategory("Permission Entity")]
        [TestMethod]
        public void AddNewPermission()
        {
            var reult = "";
            var sp = new SecurityDataProvider();
            var permission = sp.CreateNewPermission();
            permission.PermissionName = "TestPermission3";
            var res = sp.AddPermission(permission, out reult); 
            Assert.AreEqual(DataProviderOperationResult.Success,res);
        }

        [TestCategory("Permission Entity")]
        [TestMethod]
        public void DeletePermission()
        {
            var reult = "";
            var sp = new SecurityDataProvider();
            var permission = sp.CreateNewPermission();
            permission.PermissionName = "TestPermission";
            var res = sp.DeletePermission(permission.PermissionName, out reult);
            Assert.AreEqual( DataProviderOperationResult.Success,res);
        }


        [TestCategory("Authorisation Entity")]
        [TestMethod]
        public void AddAuthorisation()
        {
            var result = "";
            var sp = new SecurityDataProvider();
            var role = sp.FindRole("Default1");
            var permission = sp.FindPermission("TestPermission");
            var res = sp.AddAuthorisation(role.RoleId, permission.PermissionID, out result);

            Assert.AreEqual(DataProviderOperationResult.Success, res);
        }


    }
}
